package com.ruoyi.mq.kafka;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.Random;
import java.util.concurrent.Callable;
import java.util.regex.Pattern;

/**
 * <p>className: CgCallable</p>
 * <p>description: 多线程匹配规则</p>
 *
 * @author CG
 * @version 1.0.0
 * @date 2019-09-16 10:14
 */
public class CgCallable implements Callable<Integer> {
    private static Logger logger = LoggerFactory.getLogger(CgCallable.class);

    private String taskNum;
    private String dictVal ;
    private String msgStr ;

    public CgCallable(String taskNum, String dictVal, String msgStr){
        this.taskNum = taskNum;
        this.dictVal = dictVal;
        this.msgStr = msgStr;
    }

    @Override
    public Integer call() throws Exception {
        logger.info("taskNum：{}，dictVal:{}",taskNum,dictVal);

        int rs =  this.matchRexgex(dictVal, msgStr);
        //int next = new Random().nextInt(10);
        //Thread.sleep(100L * next);
        logger.info("call===rs:{}",rs);
        return rs;
    }

    public int matchRexgex(String rex,String src){
        boolean exists = false;
        exists = Pattern.matches(rex, src);
        if(exists){
            return 1;
        }else{
            return 0;
        }

    }


}